<?php
require_once dirname(__FILE__) . '/../../bootstrap.unit.php';
require_once FORAGE_APP_PATH . '/behaviours/test/TestBehaviourHandler.php';
require_once FORAGE_APP_PATH . '/behaviours/test/TestBehaviour.php';
require_once FORAGE_APP_PATH . '/behaviours/test/TestBehaviours.php';

class ForageBehaviourTest extends ForageUnitTestCase
{
  private $behaviours;

  public function setUp()
  {
    $this->behaviours = new ForageTestBehaviourHandler();
  }

  public function tearDown()
  {
    unset($this->behaviours);
  }

  public function testCheckingHandlerForBehavioursWithClassName()
  {
    $this->assertFalse($this->behaviours->hasBehaviour('ForageTestBehaviour'));
    $this->behaviours->addBehaviour(new ForageTestBehaviour());
    $this->assertTrue($this->behaviours->hasBehaviour('ForageTestBehaviour'));
  }

  public function testCheckingHandlerForBehavioursWithObject()
  {
    $behaviour = new ForageTestBehaviour();
    $this->assertFalse($this->behaviours->hasBehaviour($behaviour));
    $this->behaviours->addBehaviour($behaviour);
    $this->assertTrue($this->behaviours->hasBehaviour($behaviour));
  }

  public function testRemovingABehaviourByClass()
  {
    $this->behaviours->addBehaviour(new ForageTestBehaviour());
    $this->assertTrue($this->behaviours->hasBehaviour('ForageTestBehaviour'));
    $this->behaviours->removeBehaviour('ForageTestBehaviour');
    $this->assertFalse($this->behaviours->hasBehaviour('ForageTestBehaviour'));
  }

  public function testRemovingABehaviourByObject()
  {
    $behaviour = new ForageTestBehaviour();
    $this->behaviours->addBehaviour($behaviour);
    $this->assertTrue($this->behaviours->hasBehaviour($behaviour));
    $this->behaviours->removeBehaviour($behaviour);
    $this->assertFalse($this->behaviours->hasBehaviour($behaviour));
  }

  public function testCallingABehaviourMethod()
  {
    $behaviour = new ForageTestBehaviour();
    $this->behaviours->addBehaviour($behaviour);
    $this->assertTrue($this->behaviours->behaviourTest());
  }

  /**
   * @expectedException BadMethodCallException
   */
  public function testCallingABehaviourFailsWhenNotThere()
  {
    $this->behaviours->behaviourTest();
  }
}
